package zombie;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Zombie {
    private static BufferedImage imgs[];
    //    用于显示当前状态对应的图像
    private BufferedImage show = null;
    public static int x;
    public static int y;
    int index = 0;

    public static BufferedImage[] getImgs() {
        return imgs;
    }

    public BufferedImage getShow() {
        return show;
    }

    public static int getX() {
        return x;
    }

    public static int getY() {
        return y;
    }

    static {
        x = 0;
        y = 0;
        System.out.println("被实例化了");
        imgs = new BufferedImage[5];
        for (int i = 0; i < imgs.length; i++) {
            imgs[i] = loadImage("zombie0" + i + ".png");
        }
    }

    private static BufferedImage loadImage(String fileName) {
        try {
            BufferedImage img = ImageIO.read(new File("D:\\教程\\projectone\\基础\\src\\main\\java\\zombie\\"+fileName));
            return img;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
    public BufferedImage getImage(int i) {
        return imgs[i];//0-4
    }
    public void paint(Graphics g,int i) {
        System.out.println("在画了");
//        初始化在画布的位置
        g.drawImage(getImage(0), x, y, null);
    }

    public void bofang(){
        if (index == 4){
            index =0;
        }
        System.out.println(index);
        show = imgs[index];
        index+=1;
    }

    public static void main(String[] args) {
        int index = 0;
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            list.add(String.valueOf(i));
        }
        System.out.println(list.get(index++ % 5));
    }

}
